from re import compile as Regex
import numpy as np
from scipy.io import loadmat

from data import BASE_PATH, DATA_FILE

R_PARAM = Regex('g=([\d\.]+)--alpha=([\d\.]+)')
RDATA_PATH = BASE_PATH / 'mat1'

Xs = []
Ys = []
for fp in RDATA_PATH.iterdir():
    g, alpha = [float(e) for e in R_PARAM.findall(fp.name)[0]]
    Ys.append([g, alpha])

    mat = loadmat(str(fp))
    x = mat['nA']   # [1, 1024]
    Xs.append(x)

X = np.concatenate(Xs, axis=0)  # [15000, 1024]
Y = np.asarray(Ys)              # [15000, 2]
XY = np.hstack((X, Y))          # [15000, 1024+2]
XY = XY.astype(np.float32)

np.save(DATA_FILE, XY)
